//
//	Brandlist.m
//
//	Create by li cheng on 9/8/2016
//	Copyright © 2016. All rights reserved.
//	Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport



#import "Brandlist.h"

NSString *const kBrandlistLetter = @"letter";
NSString *const kBrandlistList = @"list";

@interface Brandlist ()
@end
@implementation Brandlist




/**
 * Instantiate the instance using the passed dictionary values to set the properties values
 */

-(instancetype)initWithDictionary:(NSDictionary *)dictionary
{
	self = [super init];
	if(![dictionary[kBrandlistLetter] isKindOfClass:[NSNull class]]){
		self.letter = dictionary[kBrandlistLetter];
	}	
	if(dictionary[kBrandlistList] != nil && [dictionary[kBrandlistList] isKindOfClass:[NSArray class]]){
		NSArray * listDictionaries = dictionary[kBrandlistList];
		NSMutableArray * listItems = [NSMutableArray array];
		for(NSDictionary * listDictionary in listDictionaries){
			List * listItem = [[List alloc] initWithDictionary:listDictionary];
			[listItems addObject:listItem];
		}
		self.list = listItems;
	}
	return self;
}


/**
 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
 */
-(NSDictionary *)toDictionary
{
	NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
	if(self.letter != nil){
		dictionary[kBrandlistLetter] = self.letter;
	}
	if(self.list != nil){
		NSMutableArray * dictionaryElements = [NSMutableArray array];
		for(List * listElement in self.list){
			[dictionaryElements addObject:[listElement toDictionary]];
		}
		dictionary[kBrandlistList] = dictionaryElements;
	}
	return dictionary;

}

/**
 * Implementation of NSCoding encoding method
 */
/**
 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
 */
- (void)encodeWithCoder:(NSCoder *)aCoder
{
	if(self.letter != nil){
		[aCoder encodeObject:self.letter forKey:kBrandlistLetter];
	}
	if(self.list != nil){
		[aCoder encodeObject:self.list forKey:kBrandlistList];
	}

}

/**
 * Implementation of NSCoding initWithCoder: method
 */
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
	self = [super init];
	self.letter = [aDecoder decodeObjectForKey:kBrandlistLetter];
	self.list = [aDecoder decodeObjectForKey:kBrandlistList];
	return self;

}

/**
 * Implementation of NSCopying copyWithZone: method
 */
- (instancetype)copyWithZone:(NSZone *)zone
{
	Brandlist *copy = [Brandlist new];

	copy.letter = [self.letter copyWithZone:zone];
	copy.list = [self.list copyWithZone:zone];

	return copy;
}
@end
